package com.swagger.demo.enums;

import com.swagger.demo.util.RespCode;

import java.util.HashMap;
import java.util.Map;

/**
 * creat by
 *
 * @author heyang
 * @date 2020/9/10 16:30
 */
public enum RespSupplyCode implements RespCode {
    FAIL(1, "失败", "system error ! ");
    // 成员变量
    private int code;   // 编码
    private String desc;   // 中文描述
    private String enDesc; //英文描述
    /**
     * 返回码MAP
     */
    private static Map<Integer, RespSupplyCode> map;

    static {
        //初始化
        map = new HashMap<>(values().length);
        for (RespSupplyCode respCode : RespSupplyCode.values()) {
            map.put(respCode.getCode(), respCode);
        }
    }

    private RespSupplyCode(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private RespSupplyCode(int code, String desc, String enDesc) {
        this.code = code;
        this.desc = desc;
        this.enDesc = enDesc;
    }

    public static RespCode getType(int code) {
        if (code <= 0) {
            return null;
        }
        return map.get(code);
    }

    @Override
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * 获取返回码反描述
     *
     * @param index
     * @return
     */
    public static String getDesc(int code) {
        RespCode respCode = getType(code);
        return respCode == null ? "" : respCode.getDesc();
    }

    @Override
    public String getEnDesc() {
        return enDesc;
    }

    public void setEnDesc(String enDesc) {
        this.enDesc = enDesc;
    }

    @Override
    public boolean print() {
        return false;
    }
}
